package www.woniuxy.com.class112.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import www.woniuxy.com.class112.dto.KnowledgeBaseDto;
import www.woniuxy.com.class112.entity.KnowledgeBase;
import www.woniuxy.com.class112.form.KnowledgeBasePageFrom;
import www.woniuxy.com.class112.form.QusForm;
import www.woniuxy.com.class112.param.KnowledgeBasePageParam;
import www.woniuxy.com.class112.param.QusParam;
import www.woniuxy.com.class112.service.KnowledgeBaseService;
import www.woniuxy.com.class112.util.JwtUtil;
import www.woniuxy.com.class112.util.Result;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/knowledgeBase")
@Api(tags = "知识库相关接口")
public class KnowledgeBaseController {

    @Resource
    private KnowledgeBaseService knowledgeBaseService;
    @PostMapping("/addKnowledgeBase")
    @ApiOperation("新增知识库")
    public Result addKnowledgeBase(@RequestBody QusForm form,@RequestHeader String token){
        Long userId = JwtUtil.getUserId(token);
        System.out.println(userId);
        QusParam param =BeanUtil.toBean(form, QusParam.class);
        param.setUserId(userId);
        knowledgeBaseService.addKnowledgeBase(param);

        return Result.success("新增知识库成功",null);
    }

    @PostMapping("/queryKnowledgeBase")
    @ApiOperation("查询知识库")
    public Result queryKnowledgeBase(@RequestBody KnowledgeBasePageFrom from){
        PageInfo<KnowledgeBaseDto> knowledgeBases =  knowledgeBaseService.queryKnowledgeBase(BeanUtil.toBean(from, KnowledgeBasePageParam.class));
        return Result.success("查询成功",knowledgeBases);
    }

    @GetMapping("/deleteKnowledgeBase")
    @ApiOperation("删除知识库")
    public Result deleteKnowledgeBase(Long knowledgeId){
        knowledgeBaseService.deleteKnowledgeBase(knowledgeId);
        return Result.success("删除成功",null);
    }
    @PostMapping("/compileKnowledgeBase")
    @ApiOperation("修改知识库")
    public Result compileKnowledgeBase(@RequestBody KnowledgeBase form){
        knowledgeBaseService.compileKnowledgeBase(form);
        return Result.success("修改知识库成功",null);
    }
    @GetMapping("/sss")
    public Result sss(Long id){
        KnowledgeBase bases = knowledgeBaseService.sss(id);
        return Result.success("成功",bases);
    }
}
